package com.grm.strategy.service;

import com.grm.strategy.entity.User;
import com.grm.strategy.factory.Factory;
import com.grm.strategy.handler.Handler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class TestService {
    /**
     * 最叼的写法
     *
     * @param user 用户
     * @param type 类型
     */
    public void actionBetter(User user, String type) {
        Handler handler = Factory.getInvokeStrategy(type);
        String username = handler.queryUserName(user.getUsername());
        log.info("username={}",username);
        Integer age = handler.queryAge(user.getAge());
        log.info("age={}",age);
        User userInfo = handler.queryUser(user);
        log.info("userInfo={}",userInfo);
    }
    /**
     * 最low的写法
     *
     * @param user 用户
     * @param type 类型
     */
    public void action(User user, String type) {
        if ("aaa".equals(type)) {
            String username = queryUserName(user.getUsername());
            log.info("queryUserName,username={}", username);
        } else if ("bbb".equals(type)) {
            Integer age = queryAge(user.getAge());
            log.info("queryAge,age={}", age);
        } else if ("ccc".equals(type)) {
            User userInfo = queryUser(user);
            log.info("queryUser,user={}", userInfo);
        } else {
            log.info("type is error,type={}", type);
        }
    }

    private String queryUserName(String username) {
        return username + ",,,,,,,";
    }

    private Integer queryAge(Integer age) {
        return age + 5;
    }

    private User queryUser(User user) {
        user.setId(1L);
        user.setUsername("2ww");
        user.setPhone("154286873354");
        user.setAge(16);
        return user;
    }
}
